package com.gome.boot.config.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import redis.GcacheClient;

/**
 * Redis基础配置.
 *
 * @author baoxiufeng
 */
public abstract class BaseRedisConfig {
    private static final String KEY_ZOOKEEPER_ADDRESS = "zookeeper.address";

    @Autowired
    protected Environment env;

    /**
     * 根据业务名获取Gcache客户端工具实例.
     *
     * @param businessName 业务名
     * @return 业务名对应的Gcache客户端工具实例
     */
    protected GcacheClient getClient(String businessName) {
        return new GcacheClient(env.getRequiredProperty(KEY_ZOOKEEPER_ADDRESS), businessName);
    }

    /**
     * 根据业务名KEY获取Gcache客户端工具实例.
     *
     * @param businessNameKey 业务名KEY
     * @return 业务名KEY对应的Gcache客户端工具实例
     */
    protected GcacheClient getClientByKey(String businessNameKey) {
        return new GcacheClient(env.getRequiredProperty(KEY_ZOOKEEPER_ADDRESS), env.getRequiredProperty(businessNameKey));
    }
}
